package com.zjlanyun.erp.approve;

import java.util.ArrayList;
import java.util.HashMap;

import com.zjlanyun.erp.R;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ApproveMain extends Fragment {

	private View rootView;
	private LinearLayout mainContent;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		if (rootView == null) {
			rootView = LayoutInflater.from(getActivity()).inflate(R.layout.approve_main, null);
		}
		ViewGroup parent = (ViewGroup) rootView.getParent();
		if (parent != null) {
			parent.removeView(rootView);
		}
		return rootView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		initView();
		initData();
	}

	// 初始化View
	private void initView() {
		mainContent = (LinearLayout) rootView.findViewById(R.id.content);
	}

	private void initData() {
		String[] titles = { "采购订单信息", "供应商信息", "业务员信息" };
		ArrayList<ArrayList<HashMap<String, String>>> list = new ArrayList<ArrayList<HashMap<String, String>>>();

		String[] keys = { "单据编号", "单据日期", "到货日期", "采购订金", "单据金额", "仓库名称", "制单人" };
		String[] values = { "PO-2014-07-0002", "2014-07-16", "2014-07-28", "1,000.00", "1,494.00", "零食仓", "wulic" };
		ArrayList<HashMap<String, String>> mList = new ArrayList<HashMap<String, String>>();
		for (int i = 0; i < keys.length; i++) {
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("key", keys[i]);
			map.put("value", values[i]);
			mList.add(map);
		}
		list.add(mList);

		keys = new String[] { "供应商编号", "供应商名称", "联系人", "电话" };
		values = new String[] { "wl002", "上海良品铺子电子商务有限公司", "李敏", "13600557651" };
		mList = new ArrayList<HashMap<String, String>>();
		for (int i = 0; i < keys.length; i++) {
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("key", keys[i]);
			map.put("value", values[i]);
			mList.add(map);
		}
		list.add(mList);

		keys = new String[] { "业务员", "电话" };
		values = new String[] { "王立宇", "13600557651" };
		mList = new ArrayList<HashMap<String, String>>();
		for (int i = 0; i < keys.length; i++) {
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("key", keys[i]);
			map.put("value", values[i]);
			mList.add(map);
		}
		list.add(mList);

		for (int i = 0; i < titles.length; i++) {
			LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
			View view = layoutInflater.inflate(R.layout.approve_main_item, null);

			TextView title = (TextView) view.findViewById(R.id.title);
			title.setText(titles[i]);
			LinearLayout content = (LinearLayout) view.findViewById(R.id.content);

			mList = new ArrayList<HashMap<String, String>>();
			mList = list.get(i);

			for (int j = 0; j < mList.size(); j++) {
				LayoutInflater layoutInflater2 = LayoutInflater.from(getActivity());
				View view2 = layoutInflater2.inflate(R.layout.approve_main_item_item, null);
				TextView key = (TextView) view2.findViewById(R.id.key);
				TextView value = (TextView) view2.findViewById(R.id.value);
				key.setText(mList.get(j).get("key") + " : ");
				value.setText(mList.get(j).get("value"));
				content.addView(view2);
			}
			mainContent.addView(view);
		}

	}

}
